package com.ldf.jrtsp.enums;

import com.ldf.jrtsp.conf.RtspConfig;
import com.ldf.jrtsp.exception.JRtspException;
import com.ldf.jrtsp.player.RtspPlayer;
import com.ldf.jrtsp.socket.RtspTransportFactory;

import static com.ldf.jrtsp.constants.RtspConstants.*;

/**
 * rtsp协议类型
 *
 * @author lidaofu
 * @since 2024/6/19
 **/
public enum RtspProtocolType {

    /**
     * rtsp over udp
     */
    RTSP_OVER_UDP,

    /**
     * rtsp over tcp
     */
    RTSP_OVER_TCP,

    /**
     * rtsp over multicast
     */
    RTSP_OVER_MULTICAST,

    /**
     * rtsp over http
     */
    RTSP_OVER_HTTP,

    /**
     * rtsp over websocket
     */
    RTSP_OVER_WEBSOCKET;


    /**
     * 添加transport信息
     *
     * @param sb

     */
    public int addTransportInfo(StringBuilder sb,MediaType type,int rtpPort) {
        switch (this) {
            case RTSP_OVER_UDP:
                sb.append(RTSP_UNICAST_UDP);
                if (rtpPort == -1) {
                    throw new JRtspException("no available port");
                }
                sb.append(rtpPort + "-" + (rtpPort + 1));
                return rtpPort;
            case RTSP_OVER_TCP:
                sb.append(type == MediaType.VIDEO ? RTSP_UNICAST_TCP_VIDEO : RTSP_UNICAST_TCP_AUDIO);
                return 0;
            default:
                //todo 暂不支持
                return 0;
        }
    }

}
